<?php
class reservation extends WP_Widget {

    function __construct() {
        parent::__construct(
          'reservation',
          'Đặt phòng',
          array( 'description' => 'Hướng dẫn đặt phòng', )
        );
    }

    public function widget($args, $instance) {
            extract($args);

      $title = apply_filters( 'widget_title', $instance['title'] );
      $number = $instance['number'];

            echo $before_widget . $before_title;
            if ( ! empty ( $title ) ) {
              echo $title;
            }
            echo $after_title;

        $args = array (
          'posts_per_page' => $number,
        );?>        
        <div class="reservation-sidebar">
            <h5>RESERVATION</h5>
            <p>Send us a message with your desired room type, arrival date and number of nights you’d like to reserve, and <span style="color: #0e0701; font-weight: bold;">we’ll contact you in no time.</span></p>
            <img src="<?php bloginfo("template_url"); ?>/img/reservation-side.png">
        </div>
        <?php wp_reset_postdata();

            echo $after_widget;
        }

    public function form( $instance ) {
        $title = strip_tags($instance['title']);
        if (isset( $instance[ 'number' ] ) ) {
          $number = $instance['number'];
        } else { $number = '5'; }

    ?>
    <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
    <p><em>Use the following options to customize the display.</em></p>

    <p style="border-bottom:4px double #eee;padding: 0 0 10px;">
      <label for="<?php echo $this->get_field_id( 'number' ); ?>">Số lượng bài viết cần hiển thị</label>
      <input id="<?php echo $this->get_field_id( 'number'); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" value="<?php echo esc_attr($number); ?>" type="number" style="width:100%;" /><br>
    </p>

    <?php }

    public function update( $new_instance, $old_instance ) {
        $instance = $old_instance;

        $instance['title'] = strip_tags($new_instance['title']);
        $instance['number'] = strip_tags($new_instance['number']);

        return $instance;
    }

}

function register_reservation() {
    register_widget( 'reservation' );
}
add_action( 'widgets_init', 'register_reservation' );